/**
 * 
 */
package com.jnk.space.thread;

/**
 * http://www.cnblogs.com/cr1719/p/9339887.html
 * 两条线程循环打印1-100
 * 
 * @author jiangnk001
 *
 */
public class MultiThreadPrintNumber2 {

	private static Object lock = new Object();
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		new Thread(()->{
			for(int i = 1;i < 100;i++){
				synchronized (lock) {
					lock.notify();
					System.out.println(Thread.currentThread().getName()+ " " + i++);
					try {
						lock.wait();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
		new Thread(()->{
			for(int i = 2;i <= 100;i++){
				synchronized (lock) {
					lock.notify();
					System.out.println(Thread.currentThread().getName()+ " " + i++);
					try {
						lock.wait();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
	}
}


